<html>
<head>
<script type="text/javascript"
	src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script>

	var myLatlng= new google.maps.LatLng(23.129074,113.26442);//定位到广州
	
	var map;
	
	var geocoder;
	
	function initialize() {
	
	var myOptions = {
	
	zoom: 12,
	
	center: myLatlng,
	
	mapTypeControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP };
	
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	geocoder = new google.maps.Geocoder();
	
	};
	
	window.onload = function(){
	
	initialize();
	
	};

</script>
</head>
<div id="main">
	<div class="hr">
		<hr />
	</div>
	<div id="example">

	<?php
	require 'conn.php';
	//		$admin = $_SESSION['admin'];
	//		$userid = $_SESSION['userid'];
	//		if (($admin == "") && ($userid == "")) {
	//			echo "<h2>请先登陆</h2>";
	//		}
	//		else
	//		{
	?>

	<?php
	global $query;
	$type = 0;
	$type = trim($_GET['type']);
	if ($type == 0)
	$query = "SELECT shop.*,area.area_name FROM shop,area WHERE shop.area_id=area.area_id";
	else
	$query = "SELECT shop.*,area.area_name FROM shop,area WHERE shop.area_id=area.area_id and type=".$type;

	if (isset($_GET['page'])) {
		$page = intval($_GET['page']);
	}
	else
	{
		$page = 1;
	}
	$page_count = 0;
	$page_size = $psize;
	if ($type == 0)
	$query1 = "SELECT count(*) FROM shop";
	else
	$query1 = "SELECT count(*) FROM shop WHERE type=".$type;

	$result = mysql_query($query1);
	$row = mysql_fetch_row($result);
	$amount = $row[0];
	if ($amount) {
		if ($amount < $page_size) {
			$page_count = 1;
		}
		if ($amount % $page_size) {
			$page_count = (int)($amount / $page_size) + 1;
		}
		else
		{
			$page_count = $amount / $page_size;
		}
	}
	else
	{
		$page_count = 0;
	}

	echo "<h2>";
	switch ($type) {
		case 1:
			echo "优惠活动";
			break;
		case 2:
			echo "餐饮娱乐";
			break;
		case 3:
			echo "购物丽人";
			break;
		case 4:
			echo "房屋买卖";
			break;
		case 5:
			echo "购车指南";
			break;
		case 6:
			echo "留学移民";
			break;
		default:
			;
			break;
	}

	echo "</h2>";
	echo "<blockquote>";
	echo "<p>管理员可以查看，修改和删除以下店铺</p>";
	echo "</blockquote>";
	echo "<table border=1>";
	echo "<tr>";
	echo "<td>编号</td>";
	echo "<td>名称</td>";
	echo "<td>标题</td>";
	//	echo "<td>地址</td>";
	//	echo "<td>电话</td>";
	//	echo "<td>邮件</td>";
	//	echo "<td>纬度</td>";
	//	echo "<td>经度</td>";
	//	echo "<td>创建时间</td>";
	//	echo "<td>最后修改时间</td>";
	echo "<td>描述</td>";
	//	echo "<td>详情</td>";
	echo "<td colspan=3>操作</td>";
	echo "</tr>";

	if ($amount) {
		$query2 = $query." order by shop_id desc limit ". ($page - 1)*$page_size .", $page_size";
		$result = mysql_query($query2);
		$num = mysql_num_rows($result);
		for ($i = 0; $i < $num; $i++) {
			$row = mysql_fetch_array($result);
			$id = $row['shop_id'];
			$name = $row['name'];
			$title = $row['title'];
			$address = $row['address'];
			$area = $row['area_name'];
			$telephone = $row['telephone'];
			$email = $row['email'];
			$latitude = $row['latitude'];
			$longitude = $row['longitude'];
			$createtime = $row['createtime'];
			$description = $row['description'];
			$details = $row['details'];
			$image = $row['image'];
			$favorite_count = $row['favorite_count'];
			$tap_count = $row['tap_count'];
			$lastedittime = $row['lastedittime'];

			$formatTime = date("y-m-d h:i:s",$createtime);
			$formatLastEditTime = date("y-m-d h:i:s",$lastedittime);
			echo "<tr>";
			echo "<td>".$id."</td>";
			echo "<td>".$name."</td>";
			echo "<td>".$title."</td>";
			//			echo "<td>".$address."</td>";
			//			echo "<td>".$telephone."</td>";
			//			echo "<td>".$email."</td>";
			//			echo "<td>".$latitude."</td>";
			//			echo "<td>".$longitude."</td>";
			//			echo "<td>".$formatTime."</td>";
			//			echo "<td>".$formatLastEditTime."</td>";
			echo "<td>".$description."</td>";
			//			echo "<td>".$details."</td>";
			echo "<td>";
			echo "<form action='deleteshop.php' method='post'>";
			echo "<input type='hidden' name='deleteid' value='$id'/>";
			echo "<input type='submit' value='删除'/>";
			echo "</form>";
			echo "</td>";
			echo "<td>";
			echo "<form action='editshop.php' method='post'>";
			echo "<input type='hidden' name='shop_id' value='$id'/>";
			echo "<input type='hidden' name='name' value='$name'/>";
			echo "<input type='hidden' name='title' value='$title'/>";
			echo "<input type='hidden' name='address' value='$address'/>";
			echo "<input type='hidden' name='area' value='$area'/>";
			echo "<input type='hidden' name='telephone' value='$telephone'/>";
			echo "<input type='hidden' name='email' value='$email'/>";
			echo "<input type='hidden' name='latitude' value='$latitude'/>";
			echo "<input type='hidden' name='longitude' value='$longitude'/>";
			echo "<input type='hidden' name='createtime' value='$createtime'/>";
			echo "<input type='hidden' name='lastedittime' value='$lastedittime'/>";
			echo "<input type='hidden' name='description' value='$description'/>";
			echo "<input type='hidden' name='details' value='$details'/>";
			echo "<input type='hidden' name='image' value='$image'/>";
			echo "<input type='hidden' name='favorite_count' value='$favorite_count'/>";
			echo "<input type='hidden' name='tap_count' value='$tap_count'/>";
			echo "<input type='submit' value='修改'/>";
			echo "</form>";
			echo "</td>";
			echo "<td>";
			echo "<form action='viewshop.php' method='post'>";
			echo "<input type='hidden' name='shop_id' value='$id'/>";
			echo "<input type='hidden' name='name' value='$name'/>";
			echo "<input type='hidden' name='title' value='$title'/>";
			echo "<input type='hidden' name='address' value='$address'/>";
			echo "<input type='hidden' name='area' value='$area'/>";
			echo "<input type='hidden' name='telephone' value='$telephone'/>";
			echo "<input type='hidden' name='email' value='$email'/>";
			echo "<input type='hidden' name='latitude' value='$latitude'/>";
			echo "<input type='hidden' name='longitude' value='$longitude'/>";
			echo "<input type='hidden' name='createtime' value='$createtime'/>";
			echo "<input type='hidden' name='lastedittime' value='$lastedittime'/>";
			echo "<input type='hidden' name='description' value='$description'/>";
			echo "<input type='hidden' name='details' value='$details'/>";
			echo "<input type='hidden' name='image' value='$image'/>";
			echo "<input type='hidden' name='favorite_count' value='$favorite_count'/>";
			echo "<input type='hidden' name='tap_count' value='$tap_count'/>";
				
			echo "<input type='submit' value='查看'/>";
			echo "</form>";
			echo "</td>";
			echo "</tr>";
		}

	}

	else
	{
		echo "没有记录";
	}

	echo "</table>";

	$page_string = '';
	if ($page == 1) {
		$page_string .= '第一页|上一页';
	}
	else
	{
		$page_string .= '<a href=?page=1>第一页</a>|<a href=?page='.($page - 1).'>上一页</a>|';
	}
	if (($page == $page_count) || ($page_count == 0)) {
		$page_string .= '下一页|尾页';
	}
	else
	{
		$page_string .= '<a href=?page='.($page + 1).'>下一页</a>|<a href=?page='.$page_count.'>尾页</a>|';
	}
	echo "<br>".$page_string;

	//		}
	?>

	</div>
	<!-- <div id="map_canvas" style="width:800px;height:600px;"></div> -->
</div>
</html>
